<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Example that shows the effect of scream</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="scream.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.weakref.html">Weakref</a></div>
 <div class="up"><a href="scream.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="scream.examples-simple" class="section">
  <h2 class="title">Example that shows the effect of scream</h2>
  <p class="para">
   This example demonstrates how scream affects the behaviour of PHP&#039;s  error handler.
  </p>
  <p class="para">
   <div class="example" id="example-520">
    <p><strong>Example #1 Enabling and disabling scream at runtime</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Make&nbsp;sure&nbsp;errors&nbsp;will&nbsp;be&nbsp;shown<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'display_errors'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">error_reporting</span><span style="color: #007700">(</span><span style="color: #0000BB">E_ALL</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Disable&nbsp;scream&nbsp;-&nbsp;this&nbsp;is&nbsp;the&nbsp;default&nbsp;and&nbsp;produce&nbsp;an&nbsp;error<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'scream.enabled'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Opening&nbsp;http://example.com/not-existing-file\n"</span><span style="color: #007700">;<br />@</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com/not-existing-file'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Now&nbsp;enable&nbsp;scream&nbsp;and&nbsp;try&nbsp;again<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'scream.enabled'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Opening&nbsp;http://example.com/not-existing-file\n"</span><span style="color: #007700">;<br />@</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com/another-not-existing-file'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Opening http://example.com/not-existing-file
Opening http://example.com/not-existing-file

Warning: fopen(http://example.com/another-not-existing-file): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in example.php on line 14
</pre></div>
    </div>
   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Usually one would set this in the <a href="configuration.file.html" class="link">php.ini configuration file</a>
    instead of changing the code.
    </span>
  </p></blockquote>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="scream.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.weakref.html">Weakref</a></div>
 <div class="up"><a href="scream.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
